export class SortedDictionary<K, V> {
    private Map: Map<K, V>;

    constructor() {
        this.Map = new Map<K, V>();
    }

    public Add(key: K, value: V): void {
        this.Map.set(key, value);
    }

    public Remove(key: K): void {
        this.Map.delete(key);
    }

    public Get(key: K): V | undefined {
        return this.Map.get(key);
    }

    public TryGetValue(key: K): V {
        if (this.ContainsKey(key)) {
            return this.Get(key);
        }
        return null;
    }

    public ContainsKey(key: K): boolean {
        return this.Map.has(key);
    }

    public Clear(): void {
        this.Map.clear();
    }

    public get Count(): number {
        return this.Map.size;
    }

    public get Keys(): K[] {
        return Array.from(this.Map.keys());
    }

    public get Values(): V[] {
        return Array.from(this.Map.values());
    }

    public get SortedKeys(): K[] {
        return Array.from(this.Map.keys()).sort();
    }

    public get SortedValues(): V[] {
        return this.SortedKeys.map((key) => this.Map.get(key)!);
    }
}